﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class WebUserControl_Nhapnghiepvukho : System.Web.UI.UserControl
{
    BCDataCenter.DataAccessLayer.DAL dt;
    static DataTable dt1 = null;
    static DataTable dt2 = null;
    static bool flag = false;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dt = new BCDataCenter.DataAccessLayer.DAL();
            DataSet DS = new DataSet();
            DS = dt.MyExecuteReader(ref error, "get_Intxtyp", CommandType.StoredProcedure);
            dr_loainghiepvu.DataSource = DS.Tables[0];
            dr_loainghiepvu.DataTextField = "description";
            dr_loainghiepvu.DataValueField = "trntyp";
            dr_loainghiepvu.DataBind();
            DS.Dispose();
            //---------------------
            ibt_luu.Enabled = false;
            ibt_xoa.Enabled = false;
            tb_ma.Enabled = false;
            tb_ma1.Enabled = false;
        }
    }
    public DataTable dTabledoigia()
    {
        dt1 = new DataTable();
        dt1.Columns.Add("itemkey");
        dt1.Columns.Add("description");
        dt1.Columns.Add("oldprice");
        dt1.Columns.Add("newprice");
        return dt1;
    }
    public DataTable dTablenghiepvukho()
    {
        dt2 = new DataTable();
        dt2.Columns.Add("itemkey");
        dt2.Columns.Add("description");
        dt2.Columns.Add("soluong");       
        return dt2;
    }

    protected void ibt_taomoi_Click(object sender, ImageClickEventArgs e)
    {          
        //------
        ibt_luu.Enabled = true;
        dr_songhiepvu.Enabled = false;
        flag = true;
    }
    protected void ibt_luu_Click(object sender, ImageClickEventArgs e)
    {
        //----------------
        tb_ma.Enabled = false;
        tb_ma1.Enabled = false;
        flag = false;
        dr_songhiepvu.Enabled = true;
    }
    protected void ibt_xoa_Click(object sender, ImageClickEventArgs e)
    {

    }

    protected void ibt_cancel_Click(object sender, ImageClickEventArgs e)
    {
        dr_songhiepvu.Enabled = true;
    }
    protected void dr_loainghiepvu_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (flag == true)
        {
            if (dr_loainghiepvu.SelectedValue.ToString() == "F")
            {
                dTabledoigia();
                MultiView1.ActiveViewIndex = 0;
            }
            else
            {
                if (dr_loainghiepvu.SelectedValue.ToString() == "0")
                {
                    //return;
                }
                else
                {
                    dTablenghiepvukho();
                }
                MultiView1.ActiveViewIndex = 1;
            }
        }
        else
        {
            if (dr_loainghiepvu.SelectedValue.ToString() == "F")
                MultiView1.ActiveViewIndex = 0;
            else
                MultiView1.ActiveViewIndex = 1;
            dr_songhiepvu.Enabled = true;
            DataSet ds = new DataSet();
            dt = new BCDataCenter.DataAccessLayer.DAL();
            ds = dt.MyExecuteQuery(ref error, "get_intxdtrano", CommandType.StoredProcedure, new SqlParameter("@trntyp", dr_loainghiepvu.SelectedValue.ToString()));
            if (ds.Tables[0].Rows.Count >= 1)
            {
                dr_songhiepvu.DataSource = ds.Tables[0];
                dr_songhiepvu.DataTextField = "docno";
                dr_songhiepvu.DataValueField = "trntyp";
                dr_songhiepvu.DataBind();
            }
            ds.Dispose();
        }
       
    }
    protected void dr_songhiepvu_SelectedIndexChanged(object sender, EventArgs e)
    {
        dt = new BCDataCenter.DataAccessLayer.DAL();
        DataSet ds = new DataSet();
        ds = dt.MyExecuteQuery(ref error, "P_get_intxdetail", CommandType.StoredProcedure, new SqlParameter("@docno",dr_songhiepvu.SelectedItem.Text.ToString()), new SqlParameter("@trntyp",dr_songhiepvu.SelectedValue.ToString()));
        if (ds.Tables[0].Rows.Count >= 1)
        {
            if (dr_loainghiepvu.SelectedValue == "0")
            {
            }
            else
            {
                if (dr_loainghiepvu.SelectedValue == "F")
                {
                    dt1 = new DataTable();
                    dt1 = ds.Tables[0];
                    gv_doigia.DataSource = dt1;
                    gv_doigia.DataBind();
                    ds.Dispose();
                }
                else
                {
                    dt2 = new DataTable();
                    dt2 = ds.Tables[0];
                    gv_nghiepvukho.DataSource = dt2;
                    gv_nghiepvukho.DataBind();
                    ds.Dispose();
                }
            }
        }
    }
}
